package com.test.mweb;

import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;

@RestController
public class NutchController {

	@Autowired
	private NutchService nutchService;
	
	private final Counter counter;
	
	private AtomicInteger c = new AtomicInteger(0);
	
	private Gauge gauge;
	
	public NutchController(MeterRegistry registry) {
		 this.counter = registry.counter("xxx");
		 this.gauge = Gauge.builder("sizex", c, AtomicInteger::get).register(registry);
	}


	@PostMapping("/search")
	public Page<Nutch> query(@RequestParam("content") String content) {
		return nutchService.search(content);
	}
	
	@PostMapping("/page")
	public Page<Nutch> page(@RequestParam("content") String content) {
		counter.increment();
		c.set(2000);
		return nutchService.page(content);
	}
}
